<?php

namespace Home\Controller;

/**
 * Description of AccountPageController.class控制器实例
 *
 * @author songanwei
 * @date 2016-1-6
 */
class AccountPageController extends ParentController {

    /**
     * @description 账号页面视图
     * @modify songanwei 2016-01-06
     */
    public function index() {
        $userId = getUserId();
        $hotelId = I('get.hotel');

        //查询管理客栈
        $adminHotelModel = D('AdminHotel');
        $adminHotels = $adminHotelModel->getInfosByAdmin($userId);
        //查询当前用户信息
        //$adminLoginLogic = A('Common/AdminLogin', 'Logic');
        //$adminLogin = $adminLoginLogic->getInfo($userId);
        //获取所有用户
        if ($adminHotels) {
            //获取客栈数据
            $hotelIdArr = array_column($adminHotels, 'hotelentity_id');
            $hotelLogic = A('Common/Hotel', 'Logic');
            $hotelEntitys = $hotelLogic->getHotelByHotelId($hotelIdArr);

            //获取权限数据
            $hotelAuthorityLogic = A('Common/HotelAuthority', 'Logic');
            $hotelAuthoritys = $hotelAuthorityLogic->getAuthority();
        }

        // 选择语言
        foreach ($hotelAuthoritys as $key => &$hotelAuthorityItem) {
            switch (LANG_SET) {
                case 'zh_cn':
                    $hotelAuthorityItem['name'] = explode('/', $hotelAuthorityItem['name'])[0];
                    foreach ($hotelAuthorityItem['authoritys'] as $key => &$authoritys) {
                        $authoritys['name'] = explode('/', $authoritys['name'])[0];
                    }
                    break;
                case 'en_us':
                    $hotelAuthorityItem['name'] = explode('/', $hotelAuthorityItem['name'])[1];
                    foreach ($hotelAuthorityItem['authoritys'] as $key => &$authoritys) {
                        $authoritys['name'] = explode('/', $authoritys['name'])[1];
                    }
                    break;
                case 'zh_tw':
                    $hotelAuthorityItem['name'] = explode('/', $hotelAuthorityItem['name'])[2];
                    foreach ($hotelAuthorityItem['authoritys'] as $key => &$authoritys) {
                        $authoritys['name'] = explode('/', $authoritys['name'])[2];
                    }
                    break;
                default:
                    $hotelAuthorityItem['name'] = explode('/', $hotelAuthorityItem['name'])[0];
                    foreach ($hotelAuthorityItem['authoritys'] as $key => &$authoritys) {
                        $authoritys['name'] = explode('/', $authoritys['name'])[0];
                    }
                    break;
            }
        }
        unset($hotelAuthorityItem);

        $this->assign('hotelAuthoritys', $hotelAuthoritys);
        $this->assign('hotelEntitys', $hotelEntitys);
        //$this->assign('adminLogin', $adminLogin);
        $this->display();
    }

}
